ChannelAn audio routing unit that can host an effect chain, attach audio clips via an internal AudioClipPlayer, and send its output to another Channel or the Master.
import { Channel } from "@fluex/fluexgl-dsp";
const channel = new Channel(context);
channel.send(master);
Constructs a new Channel and initializes its internal audio nodes (input → effects → panner → analyser → gain → output) and its AudioClipPlayer.
new Channel(context: AudioContext, label?: string): Channel;
context: AudioContext - The AudioContext used to create this channel's internal audio nodes.label?: string - Optional label for this channel. Defaults to "Channel".id: stringA unique id, automatically generated when constructing a new channel. Should NOT be changed.
label: stringA custom label for this channel. Can be changed.
input: AudioNode | nullInput node for this channel. Internally created as a GainNode and used as the start of the routing chain.
stereoPannerNode: StereoPannerNode | nullStereo panner node for left/right balance control inside this channel.
analyserNode: AnalyserNode | nullAnalyser node used for visualization / analysis of this channel's signal.
gainNode: GainNode | nullGain node used to control the channel's volume after analysis.
output: AudioNode | nullOutput node of this channel. This node is connected to other channels when calling send().
effects: Effector[]List of attached Effector instances. These are wired between input and stereoPannerNode.
context: AudioContext | nullThe AudioContext this channel was constructed with.
sends: Channel[]Channels this channel is currently connected to via send().
audioClipPlayer: AudioClipPlayer | nullAudioClipPlayer owned by this channel. Used to attach and play AudioClip instances into this channel.
addEffect(effect: Effector): ChannelAdds an Effector to this channel, initializes it using this channel's AudioContext, and rebuilds the internal effect chain routing. Throws if the channel has no AudioContext or if the effect was already added.
effect: Effector - The effect instance to add.Channel - The same channel. Can be used to stack methods.attachEffect(effect: Effector): ChannelAlias for addEffect(effect).
effect: Effector - The effect instance to attach.Channel - The same channel. Can be used to stack methods.removeEffect(effect: Effector): voidRemoves an attached Effector from this channel, disconnects its audio node, and rebuilds the internal effect chain routing. Logs an error if the effect is not part of this channel.
effect: Effector - The effect instance to remove.voidremoveAllEffects(): voidRemoves every effect currently attached to this channel by calling removeEffect() for each one.
No arguments
voiddetachEffect(effect: Effector): voidAlias for removeEffect(effect).
effect: Effector - The effect instance to detach.voiddetachAllEffects(): voidAlias for removeAllEffects().
No arguments
voidrebuildEffectChain(): voidPublicly re-runs the internal effect chain rebuild (reconnects input through the active effects into stereoPannerNode). Useful if the automatic rebuild did not run as expected.
No arguments
voidsend(channel: Channel | Master): voidConnects this channel's output to another Channel (to its input) or to the Master. Prevents self-links, mismatched AudioContexts, duplicate links, and feedback loops.
voidunsend(channel: Channel | Master): voidDisconnects this channel from a previously linked Channel or Master and removes it from sends.
voidunsendToAllChannels(): voidDisconnects this channel from all channels currently stored in sends.
No arguments
voidhasAudioClipPlayer(): booleanReturns whether this channel has a constructed AudioClipPlayer.
No arguments
boolean - true if audioClipPlayer is defined, otherwise false.attachAudioClip(audioClip: AudioClip): ChannelAttaches an AudioClip to this channel via its internal AudioClipPlayer. Throws if this channel has no audioClipPlayer.
audioClip: AudioClip - The audio clip to attach.Channel - The same channel. Can be used to stack methods.volume(volume?: number): numberGets or sets this channel's gain. When volume is provided (and truthy), it is written to gainNode.gain at the current context time. Throws if the channel has no context or gainNode.
volume?: number - New gain value to apply. Omit to just read the current value.number - The value that was set, or the current gainNode.gain.value when no argument is given.pan(pan?: number): numberGets or sets this channel's stereo pan. When pan is provided (and truthy), it is written to stereoPannerNode.pan at the current context time. Throws if the channel has no context or stereoPannerNode.
pan?: number - New pan value to apply (between -1 and 1). Omit to just read the current value.number - The value that was set, or the current stereoPannerNode.pan.value when no argument is given.getEffectsByLabel(label: string): Effector[]Returns all attached effects whose label matches the given value.
label: string - The label to match against.Effector[]getFirstEffectByLabel(label: string): Effector | nullReturns the first attached effect whose label matches the given value, or null if none match.
label: string - The label to match against.Effector | nullgetEffectById(id: string): Effector[]Returns all attached effects whose id matches the given value.
id: string - The effect id to match against.Effector[]getFirstEffectById(id: string): Effector | nullReturns the first attached effect whose id matches the given value, or null if none match.
id: string - The effect id to match against.Effector | nullmoveEffectToIndex(effect: Effector, index: number | ArrayPosition): voidMoves an already-attached effect to a new position in the effects chain and rebuilds the routing. Throws if the effect cannot be found, or if more than one effect shares the same id.
effect: Effector - The effect to move. Must already be attached to this channel.index: number | ArrayPosition - Either an absolute array index, or one of the named positions "start", "end", "one-after-start", "one-before-end". Out-of-range numeric indexes are clamped.voidThis class does not emit custom events.
This class does not define public getters or setters.
import { DspPipeline, Channel } from "@fluex/fluexgl-dsp";
(async function () {
const pipeline = new DspPipeline({
pathToWasm: "/FluexGL-DSP-WASM/fluexgl-dsp-wasm_bg.wasm",
pathToWorklet: "/FluexGL-DSP-WASM/fluexgl-dsp-processor.worklet",
options: {
overrideMaxAudioBufferNodes: true
}
});
await pipeline.initializeDpsPipeline();
const audioDevice = await pipeline.resolveDefaultAudioOutputDevice();
if (!audioDevice) return;
const context = audioDevice.getContext();
const master = audioDevice.getMasterChannel();
const channel = new Channel(context);
channel.send(master);
})()
import { DspPipeline } from "@fluex/fluexgl-dsp";
(async function () {
const pipeline = new DspPipeline({
pathToWasm: "/FluexGL-DSP-WASM/fluexgl-dsp-wasm_bg.wasm",
pathToWorklet: "/FluexGL-DSP-WASM/fluexgl-dsp-processor.worklet",
options: {
overrideMaxAudioBufferNodes: true
}
});
await pipeline.initializeDpsPipeline();
const audioDevice = await pipeline.resolveDefaultAudioOutputDevice();
if (!audioDevice) return;
const context = audioDevice.getContext();
const master = audioDevice.getMasterChannel();
const channel = audioDevice.createChannel();
channel.send(master);
})()
import { DspPipeline } from "@fluex/fluexgl-dsp";
(async function () {
const pipeline = new DspPipeline({
pathToWasm: "/FluexGL-DSP-WASM/fluexgl-dsp-wasm_bg.wasm",
pathToWorklet: "/FluexGL-DSP-WASM/fluexgl-dsp-processor.worklet",
options: {
overrideMaxAudioBufferNodes: true
}
});
await pipeline.initializeDpsPipeline();
const audioDevice = await pipeline.resolveDefaultAudioOutputDevice();
if (!audioDevice) return;
const master = audioDevice.getMasterChannel();
const channel1 = audioDevice.createChannel();
const channel2 = audioDevice.createChannel();
const channel3 = audioDevice.createChannel();
channel1.send(channel2);
channel2.send(channel3);
channel3.send(master);
})()